/**
 * @author zhoutao
 *  2010-11-20
 */
package com.jlt.entity.sys;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.jlt.entity.BaseEntity;

/**
 * 菜单
 * 
 * @author zhoutao
 * 
 */
@Entity
// 表名与类名不相同时重新定义表名.
@Table(name = "menus")
// 默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Menu extends BaseEntity {
	@Column(nullable = false)
	private String name;// 部门名称
	private String url;// 菜单url
	private String description;// 备注
	private String authorityCode;// 授权代码，用于判断菜单是否有权限显示
	private String status;// 是否可用
	private Menu parentMenu;// 父菜单
	private List<Menu> childMenuList;// 子菜单集合

	// 多对一定义
	@ManyToOne
	@JoinColumn(name = "parent_id")
	// 集合按id排序.
	@OrderBy("orderNo")
	// 集合中对象id的缓存.
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public Menu getParentMenu() {
		return parentMenu;
	}

	public void setParentMenu(Menu parentMenu) {
		this.parentMenu = parentMenu;
	}

	// 一对多定义
	@OneToMany(cascade =CascadeType.ALL,fetch=FetchType.EAGER,mappedBy = "parentMenu")
	@Fetch(FetchMode.SUBSELECT)
	// 集合按orderNo排序.
	@OrderBy("orderNo")
	// 集合中对象id的缓存.
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Menu> getChildMenuList() {
		return childMenuList;
	}

	public void setChildMenuList(List<Menu> childMenuList) {
		this.childMenuList = childMenuList;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getAuthorityCode() {
		return authorityCode;
	}

	public void setAuthorityCode(String authorityCode) {
		this.authorityCode = authorityCode;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

}
